From: Benjamin Otte Date: Mon, 13 Dec 2021 00:43:24 +0000 (+0100) Subject: x11: Explicitly close_async() the output stream X-Git-Tag: archive/raspbian/4.6.5+ds-1+rpi1~1^2~91^2^2~65^2~2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=66f1fef0830337de50731d0e44d5f1b133fe5208;p=gtk4.git x11: Explicitly close_async() the output stream We need to be very careful when writing data, because if we aren't, sync functions will be called on the output stream and X11 does not like that at all. --- diff --git a/gdk/x11/gdkclipboard-x11.c b/gdk/x11/gdkclipboard-x11.c index 404c8c7cd6..4335674102 100644 --- a/gdk/x11/gdkclipboard-x11.c +++ b/gdk/x11/gdkclipboard-x11.c @@ -76,11 +76,30 @@ print_atoms (GdkX11Clipboard *cb, }); } +static void +gdk_x11_clipboard_default_output_closed (GObject *stream, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + + if (!g_output_stream_close_finish (G_OUTPUT_STREAM (stream), result, &error)) + { + GDK_NOTE (CLIPBOARD, + g_printerr ("-------: failed to close stream: %s\n", + error->message)); + g_error_free (error); + } + + g_object_unref (stream); +} + static void gdk_x11_clipboard_default_output_done (GObject *clipboard, GAsyncResult *result, gpointer user_data) { + GOutputStream *stream = user_data; GError *error = NULL; if (!gdk_clipboard_write_finish (GDK_CLIPBOARD (clipboard), result, &error)) @@ -90,6 +109,12 @@ gdk_x11_clipboard_default_output_done (GObject *clipboard, GDK_X11_CLIPBOARD (clipboard)->selection, error->message)); g_error_free (error); } + + g_output_stream_close_async (stream, + G_PRIORITY_DEFAULT, + NULL, + gdk_x11_clipboard_default_output_closed, + NULL); } static void @@ -103,8 +128,7 @@ gdk_x11_clipboard_default_output_handler (GOutputStream *stream, G_PRIORITY_DEFAULT, NULL, gdk_x11_clipboard_default_output_done, - NULL); - g_object_unref (stream); + stream); } static GInputStream * diff --git a/gdk/x11/gdkdrag-x11.c b/gdk/x11/gdkdrag-x11.c index 5804085a56..7e7904904b 100644 --- a/gdk/x11/gdkdrag-x11.c +++ b/gdk/x11/gdkdrag-x11.c @@ -1612,11 +1612,30 @@ gdk_x11_drag_set_hotspot (GdkDrag *drag, } } +static void +gdk_x11_drag_default_output_closed (GObject *stream, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + + if (!g_output_stream_close_finish (G_OUTPUT_STREAM (stream), result, &error)) + { + GDK_NOTE (DND, + g_printerr ("failed to close stream: %s\n", + error->message)); + g_error_free (error); + } + + g_object_unref (stream); +} + static void gdk_x11_drag_default_output_done (GObject *drag, GAsyncResult *result, gpointer user_data) { + GOutputStream *stream = user_data; GError *error = NULL; if (!gdk_drag_write_finish (GDK_DRAG (drag), result, &error)) @@ -1624,6 +1643,12 @@ gdk_x11_drag_default_output_done (GObject *drag, GDK_DISPLAY_NOTE (gdk_drag_get_display (GDK_DRAG (drag)), DND, g_printerr ("failed to write stream: %s\n", error->message)); g_error_free (error); } + + g_output_stream_close_async (stream, + G_PRIORITY_DEFAULT, + NULL, + gdk_x11_drag_default_output_closed, + NULL); } static void @@ -1637,8 +1662,7 @@ gdk_x11_drag_default_output_handler (GOutputStream *stream, G_PRIORITY_DEFAULT, NULL, gdk_x11_drag_default_output_done, - NULL); - g_object_unref (stream); + stream); } static gboolean